#ifndef MAINGAME_H
#define MAINGAME_H

#include "../../Utility/Misc/Graph.h"
#include "../../EventSystem/Event.h"
#include "../../Utility/Misc/DynArray.h"

#include "BaseState.h"

#include <string>
#include <vector>
#include <queue>
using namespace std;

struct SelectedLetter
{
	char letter;
	int arrIndex;
};

class MainGame : public BaseState
{
public:
	MainGame();
	~MainGame();
	MainGame(const MainGame&);
	MainGame& operator=(const MainGame&);

	static MainGame* GetInstance();
	void Initialize();
	void InitializeGrabBag();
	void Update(float _dt);
	void Render();
	void Shutdown();
	void CheckBoard();
	void SelectLetter(bool _doubleClick, int _selectedIndex);
	void CheckSelectedWord();
	void RemoveLetters();
	void RemoveLetter(int& _indexAbove, int& _currentIndex);
	int GetValueOfLetter(char _letter);
	void StartNewGame();

	bool AddLetterToColumn(char _letter, int _column);
	bool DropLetter(int& _currentIndex);
	void SwapLetters();
	bool ClickedOnLetter(int& _selectedIndex);

	void SortWord(int _start, int _end);
	void Swap(int _index1, int _index2);

	static void HandleKeyInput(Event* _event);

private:
	//IMAGES
	int boardImage;
	vector<int> letterImages;
	int selectedImage;
	int nextTileImage;
	vector<int> numberImages;
	int gameOverImage;
	int doubleClickImage;

	int numberOfLettersOnBoard;
	int score;
	int lettersDropped;
	float doubleClickTimer;
	bool renderDoubleClick;

	DynArray<char> board;
	Graph<char> boardGrid;
	vector<SelectedLetter> selectedLetters;
	SelectedLetter swapLetter;
	vector<char> lettersGrabBag;
	char upcomingLetters[3];
};
#endif